//
// Created by yyc on 25-8-5.
//

#include "vofa_command.h"

#include <stdlib.h>
#include <string.h>
#include "angle_upload.h"
#include "servo_control.h"
#include "usart.h"
uint8_t RxBuf[32];



  // 当前角度
void vofa_command_init()
{
    HAL_UARTEx_ReceiveToIdle_DMA(&huart1, RxBuf, sizeof(RxBuf));
}
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)//接收angle的大小
{

    if(huart == &huart1)
    {
        RxBuf[Size] = '\0';
        if (strncmp((char*)RxBuf, "ANG:", 4) == 0)
        {

            int ang = atoi((char*)&RxBuf[4]);
            if(ang >= 0 && ang <= 180)
            {
                angle = ang;
                servo_set_angle(angle);
            }
        }
        HAL_UARTEx_ReceiveToIdle_DMA(&huart1, RxBuf, sizeof(RxBuf));
    }
}